package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.dev.ReSave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyh
 * @version 1.0
 */
@SuppressWarnings({"all"})
@RestController("adminOrderController")
@Slf4j
@Api(tags = "客户端订单接口")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @ApiOperation("搜索订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> pageSelect(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("搜索订单");
        PageResult pageResult = orderService.pageSelect(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("根据id查询订单")
    @GetMapping("/details/{id}")
    public Result<OrderVO> selectById(@PathVariable Integer id) {
        log.info("根据id查询订单{}", id);
        OrderVO orderVO = orderService.selectDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("取消订单{}", ordersRejectionDTO);
        orderService.cancel(ordersRejectionDTO);
        return Result.success();
    }
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> selectByStatus() {
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO orderStatisticsVO = orderService.selectByStatus();
        return Result.success(orderStatisticsVO);
    }
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result TakeOrders(@RequestBody Orders orders){
        log.info("接单");
        orderService.takeOrder(orders);
        return Result.success();
    }
    @ApiOperation("派单")
    @PutMapping("/delivery/{id}")
    public Result DeliverOrder(@PathVariable Long id){
        log.info("派单");
        orderService.DeliverOrder(id);
        return Result.success();
    }
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result CompleteOrder(@PathVariable Long id){
        log.info("完成订单");
        orderService.CompleteOrder(id);
        return Result.success();
    }
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单");
        orderService.rejectOrder(ordersRejectionDTO);
        return Result.success();
    }
}
